/*
 * @Author: mylesshie@gmail.com
 * @Date: 2020-07-03 10:39:40
 * @LastEditors: mylesshie@gmail.com
 * @LastEditTime: 2020-09-25 23:23:25
 * @description:
 */

import {
  GET_USERINFO,
  UPDATE_PSD,
  UPDATE_PHONE_BY_MSG,
  UPDATE_PHONE_BY_MSG_CHECK,
  UPDATE_PSD_BY_MSG,
  UPDATE_PSD_BY_MSG_CHECK,
  UPDATE_USERINFO,
  ADD_PHONE_BY_MSG,
  ADD_PHONE_BY_MSG_CHECK,
  LOGIN_BY_PSD,
  LOGIN_BY_PHONE,
  LOGIN_BY_PHONE_SEND_CODE,
  REGISTE_SEND_CODE,
  REGISTE,
  GET_FEEDBACK_LIST,
  SUBMIT_FEEDBACK,
  GET_COLLECTION,
  GET_COMMENT_LIST,
  GET_ARTICLE_COMMENTS,
  SUBMIT_COMMENT,
  SUBMIT_LIKE_COMMENT,
  CANCEL_LIKE_COMMENT,
  ADD_COLLECTION,
  DEL_COLLECTION,

  ADD_HISTORY,
  LOGOUT,
  GET_MESSAGES,
  UPLOAD_FILE,
  SUBMIT_BLOCK,

  WECHAT_LOGIN
} from '@/constants/user'
import createAction from '@/libs/createAction'

/**
 * @description: 获取用户信息
 * @param {type}
 */
export const getUserInfo = () =>
  createAction({
    type: GET_USERINFO,
    url: '/ct/user/customer-info/getUserInfo'
  })

/**
 * @description: 通过原密码修改密码
 * @param {type}
 */
export const updatePsd = params =>
  createAction({
    type: UPDATE_PSD,
    url: '/ct/user/customer-info/updatePassword',
    params: {
      macCode: 'string',
      password: 'string',
      startPassword: 'string',
      uid: 0,
      username: 'string'
    }
  })

/**
 * @description: 修改手机号，原手机发短信
 * @param {type}
 */
export const updatePhoneOldSendCode = phone =>
  createAction({
    type: UPDATE_PHONE_BY_MSG,
    url: `/ct/user/customer-info/updatePhoneByMsg?phone=${phone}`,
    params: {
      phone
    }
  })

/**
 * @description: 修改手机号：原手机验证短信
 * @param {type}
 */
export const updatePhoneOldCheck = (phone, msgCode) =>
  createAction({
    type: UPDATE_PHONE_BY_MSG_CHECK,
    url: '/ct/user/customer-info/updatePhoneByMsgCheck',
    params: {
      phone,
      msgCode
    }
  })

/**
 * @description: 绑定手机号：发短信
 * @param {type}
 */
export const addPhoneSendCode = phone =>
  createAction({
    type: ADD_PHONE_BY_MSG,
    url: `/ct/user/customer-info/addPhoneByMsg?phone=${phone}`,
    params: {
      phone
    }
  })

/**
 * @description: 绑定手机号：验证短信
 * @param {type}
 */
export const addPhoneCheck = (phone, msgCode) =>
  createAction({
    type: ADD_PHONE_BY_MSG_CHECK,
    url: '/ct/user/customer-info/addPhoneByMsgCheck',
    params: {
      phone,
      msgCode
    }
  })

/**
 * @description: 用手机号修改密码： 发短信
 * @param {type}
 */
export const updatePsdSendCode = () =>
  createAction({
    type: UPDATE_PSD_BY_MSG,
    url: '/ct/user/customer-info/updatePwdByMsg'
  })

/**
 * @description: 用手机号修改密码：验证短信并提交新密码
 * @param {type}
 */
export const updatePsdCheck = (macCode, password) =>
  createAction({
    type: UPDATE_PSD_BY_MSG_CHECK,
    url: '/ct/user/customer-info/updatePwdByMsgCheck',
    params: {
      macCode,
      password
    }
  })

/**
 * @description: 更新指定的用户信息
 * @param {type}
 */
export const updateUserInfo = param =>
  createAction({
    type: UPDATE_USERINFO,
    url: '/ct/user/customer-info/updateUserInfo',
    params: param
  })

/**
 * @description: 用户用密码登录
 * @param {type}
 */
export const loginByPsd = (username, password) =>
  createAction({
    type: LOGIN_BY_PSD,
    url: '/ct/user/login-info/loginAccountAndPwd',
    params: {
      username,
      password
    }
  })

/**
 * @description: 用户用手机短信登录验证短信
 * @param {type}
 */
export const loginByPhone = (username, macCode) =>
  createAction({
    type: LOGIN_BY_PHONE,
    url: '/ct/user/login-info/loginPhone',
    params: {
      username,
      macCode
    }
  })

/**
 * @description: 手机短信登录发送短信
 * @param {type}
 */
export const loginByPhoneSendCode = phone =>
  createAction({
    type: LOGIN_BY_PHONE_SEND_CODE,
    url: `/ct/user/login-info/loginMsg?phone=${phone}`,
    params: {
      phone
    }
  })

/**
 * @description: 注册时发送短信
 * @param {type}
 */
export const registeSendCode = phone =>
  createAction({
    type: REGISTE_SEND_CODE,
    url: `/ct/user/login-info/registerMsg?phone=${phone}`,
    params: {
      phone
    }
  })

/**
 * @description: 提交注册
 * @param {type}
 */
export const registe = (username, password, macCode) =>
  createAction({
    type: REGISTE,
    url: '/ct/user/login-info/registerPhone',
    params: {
      username,
      password,
      macCode
    }
  })

/**
 * @description: 提交反馈
 * @param {type}
 */
export const submitFeedback = (sugDesc, phone, qq) =>
  createAction({
    type: SUBMIT_FEEDBACK,
    url: '/ct/usercenter/suggest-info/userSuggest',
    params: {
      sugDesc,
      phone,
      qq
    }
  })

/**
 * @description: 获取我的反馈列表
 * @param {type}
 */
export const getFeedbackList = (pageNum, pageSize) =>
  createAction({
    type: GET_FEEDBACK_LIST,
    url: '/ct/usercenter/suggest-info/mySuggestList',
    params: {
      pageNum,
      pageSize
    }
  })

/**
 * @description: 获取收藏列表
 * @param {type} 
 */
export const getCollection = (pageNum, pageSize) => createAction({
  type: GET_COLLECTION,
  url: '/ct/user/collection-info/myCollectionList',
  params: {
    pageNum,
    pageSize
  }
})
/**
 * @description: 获取我的评论列表
 * @param {type} 
 */
export const getCommentList = (pageNum, pageSize) => createAction({
  type: GET_COMMENT_LIST,
  url: '/ct/comments/comment-info/myCommentList',
  params: {
    pageNum,
    pageSize
  }
})

/**
 * @description: 发起评论
 * @param {type} 
 */
export const submitComment = (articleId, commentDesc) => createAction({
  type: SUBMIT_COMMENT,
  url: '/ct/comments/comment-info/comment',
  params: {
    articleId,
    commentDesc
  }
})

/**
 * @description: 根据帖子id获取评论列表
 * @param {type} 
 */
export const getArticleComments = (articleId, pageNum, pageSize) => createAction({
  type: GET_ARTICLE_COMMENTS,
  url: '/ct/comments/comment-info/getCommentByArticleId',
  params: {
    articleId,
    pageNum,
    pageSize
  }
})

/**
 * @description: 点赞评论
 * @param {type} 
 */
export const submitLike = id => createAction({
  type: SUBMIT_LIKE_COMMENT,
  url: `/ct/comments/comment-info/commentPraise?id=${id}`,
  // params: {
  //   id
  // }
})

/**
 * @description: 取消点赞
 * @param {type} 
 */
export const cancelLike = id => createAction({
  type: CANCEL_LIKE_COMMENT,
  url: `/ct/comments/comment-info/delPraise?id=${id}`,
  params: {
    id
  }
})

/**
 * @description: 添加收藏
 * @param {type} 
 */
export const addCollection = id => createAction({
  type: ADD_COLLECTION,
  url: `/ct/user/collection-info/addCollection?id=${id}`,
  params: {
    id
  }
}) 

/**
 * @description: 取消收藏
 * @param {type} 
 */
export const delCollection = id => createAction({
  type: DEL_COLLECTION,
  url: `/ct/user/collection-info/delCollection?id=${id}`,
  params: {
    id
  }
}) 

// 本地事件
/**
 * @description: 添加浏览记录
 * @param {type} 
 */
export const addHistory = (id, title, coverImgs, type) => {
  return {
    type: ADD_HISTORY,
    params: {
      id,
      title,
      coverImgs,
      type
    }
  }
}

/**
 * @description: 用户登出
 * @param {type} 
 */
export const logout = () => {
  return {
    type: LOGOUT
  }
}

/**
 * @description: 获取消息列表
 * @param {type} 
 */
export const getMessages = (pageNum, pageSize) => createAction({
  type: GET_MESSAGES,
  url: `/ct/user/jpush/getPushMsgList`,
  params: {
    pageNum,
    pageSize
  }
})


/**
 * @description: 上传文件
 * @param {type} 
 */
export const uploadFile = (file, type, fileName) => createAction({
  type: UPLOAD_FILE,
  url: `/manager/file/uploadImg`,
  form: true,
  params: {
    file,
    type,
    fileName
  }
})

/**
 * @description: 举报
 * @param {type} 
 */
export const submitBlock = id => createAction({
  type: SUBMIT_BLOCK,
  url: `/ct/comments/comment-info/tipOff?id=${id}`
})

/**
 * @description: 微信登录
 * @param {type} 
 */
export const wechatLogin = code => createAction({
  type: WECHAT_LOGIN,
  url: `/ct/user/login-info/wechatLogin`,
  params: {
    wechatCode: code
  }
})